<template>
  <div class="course_det">
    <navigate>课程详情</navigate>
    <div>
      <div class="introduce_box white_box">
        <div class="dis_flex">
          <div class="theme_tit">主题：{{ courseInfo.name }}</div>
          <div class="collect_box dis_flex just_cont_center">
            <img src="@/assets/images/function/collect.png" alt="" class="collect_img" v-if="courseInfo.is_collect == 1"
              @click="toCollect" />
            <img src="@/assets/images/function/no_collect.png" alt="" class="collect_img" v-else @click="toCollect" />
            <div class="collect_txt">收藏课程</div>
          </div>
        </div>
        <img :src="courseInfo.cover" alt="" class="course_img">
        <div>
          <div class="introduce_txt">课程简介</div>
          <div class="introduce_desc">
            {{ courseInfo.introduce }}
          </div>
        </div>
      </div>
      <div>
        <div class="head_label dis_flex">
          <img src="@/assets/images/common/bar.png" alt="" class="label_img" />
          <div class="label_txt">课程基本信息</div>
        </div>
        <div class="info_box white_box">
          <div class="basic_info dis_flex just_cont_spa_bet">
            <div class="info_txt">课程作者：</div>
            <div>{{ courseInfo.editor }}</div>
          </div>
          <div class="basic_info dis_flex just_cont_spa_bet">
            <div class="info_txt">包含章节数：</div>
            <div>{{ courseInfo.chapter?.length }}</div>
          </div>
          <div class="basic_info dis_flex just_cont_spa_bet">
            <div class="info_txt">学习过的总人数：</div>
            <div>{{ courseInfo.study_num }}</div>
          </div>
          <div class="basic_info dis_flex just_cont_spa_bet">
            <div class="info_txt">我已学习的章节：</div>
            <div>{{ courseInfo.learning_num }}/{{ courseInfo.chapter?.length }}</div>
          </div>
        </div>
      </div>

      <div>
        <div class="head_label dis_flex">
          <img src="@/assets/images/common/bar.png" alt="" class="label_img" />
          <div class="label_txt">课程章节目录</div>
        </div>
        <div class="chapter_list">
          <div class="item_chapter white_box" v-for="(item, index) in courseInfo.chapter" :key="index">
            <div class="chapter_num">第{{ item.num }}章节</div>
            <div class="chapter_tit">
              {{ item.name }}
            </div>
            <div class="chapter_author">章节作者：{{ item.editor }}</div>
            <div class="chapter_info dis_flex">
              <img :src="item.cover" alt="" class="chapter_img" />
              <div class="chapter_desc">
                {{ item.introduce }}
              </div>
            </div>
            <div class="evaluation_task">
              附加测评任务：{{ item.rating_scale_name }} {{ item.result_id > 0 ? '【已完成】' : '【未完成】' }}
            </div>
            <div class="line"></div>
            <div class="dis_flex just_cont_spa_bet">
              <div class="dis_flex">
                <img src="@/assets/images/function/course_green_check.png" alt="" class="state_img"
                  v-if="item.is_learning == 1" />
                <img src="@/assets/images/function/course_orange_check.png" alt="" class="state_img" v-else />
                <div class="learn_state" v-if="item.is_learning == 1">本章节已学习</div>
                <div class="learn_state no_learn_state" v-else>本章节未学习</div>
              </div>
              <div class="learn_btn dis_flex just_cont_center" @click="toCapterDetPage(item)">
                <img src="@/assets/images/function/courseware.png" class="learn_img" />
                <div class="">章节学习</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="no_data_txt">-- 无更多课程章节了 --</div>
    </div>
  </div>
</template>

<script>
import { queryCourseDatails, collectCourse } from '@/api/funcation/psychologySchool'
export default {
  data() {
    return {
      courseId: '',
      courseInfo: {}
    };
  },
  created() {
    this.courseId = this.$route.query.id
    this.getCourseDatails()
  },
  methods: {
    async toCollect() {
      let par = {
        id: this.courseId,
        status: this.courseInfo.is_collect == 1 ? 0 : 1
      }
      let res = await collectCourse(par)
      if (res.code == 200) {
        this.$toast.success("操作成功！");
        this.getCourseDatails()
      }
    },
    //详情
    async getCourseDatails() {
      let res = await queryCourseDatails({
        id: this.courseId
      })
      if (res.code == 200) {
        this.courseInfo = res.data
      }
    },
    toCapterDetPage(item) {
      this.$router.push(`/chapterDet?id=${item.id}`);
    }
  }
};
</script>

<style lang="less" scoped>
.white_box {
  background: #ffffff;
  border-radius: 6.67px;
}

.dis_flex {
  display: flex;
  align-items: center;
}

.just_cont_spa_bet {
  justify-content: space-between;
}

.just_cont_center {
  justify-content: center;
}

.course_det {
  padding: 10px 10px 0 10px;
  background-color: #f4f6fa;
  color: #333333;
}

.introduce_box {
  padding: 16px 10px;
}

.collect_box {
  flex-direction: column;
  margin-left: 38px;
}

.theme_tit {
  flex: 1;
  line-height: 21.33px;
  font-size: 16.67px;
  font-weight: bold;
}

.collect_img {
  display: block;
  width: 16.67px;
  height: 16.67px;
}

.collect_txt {
  font-size: 11.33px;
  font-size: 11.33px;
  margin-top: 8px;
}

.course_img {
  width: 100%;
  height: 180px;
  margin: 14.33px 0 16.67px;
}

.introduce_txt {
  line-height: 14.67px;
}

.introduce_txt,
.introduce_desc {
  font-size: 14.67px;
}

.introduce_desc {
  margin-top: 19px;
  line-height: 28px;
}

.head_label {
  margin: 19px 0;
}

.label_img {
  width: 5.33px;
  height: 15.33px;
  margin-right: 11.33px;
}

.label_txt {
  font-weight: bold;
  font-size: 14.67px;
  line-height: 14.67px;
}

.info_box {
  padding: 0 10px;
}

.basic_info {
  font-size: 14.67px;
  height: 46px;
  border-bottom: 0.33px solid #dddddd;

  &:last-child {
    border: 0;
  }
}

.info_txt {
  color: #666666;
}

.item_chapter {
  padding: 17px 13.33px 6.67px 46.67px;
  margin-bottom: 10px;
}

.chapter_num {
  font-size: 16.67px;
  line-height: 16.67px;
}

.chapter_tit {
  font-size: 14.67px;
  line-height: 14.67px;
  margin: 18.67px 0 12.33px;
}

.chapter_author {
  font-size: 12px;
  line-height: 12px;
  color: #777777;
}

.chapter_info {
  margin: 9.67px 0 13px;
}

.chapter_img {
  width: 106.67px;
  height: 60px;
  margin-right: 10px;
}

.chapter_desc,
.evaluation_task {
  font-size: 12px;
  color: #777777;
  line-height: 22px;
}

.evaluation_task {
  line-height: 12px;
}

.line {
  border-bottom: 0.33px solid #dddddd;
  margin: 10px 0 6.67px;
}

.state_img {
  width: 14px;
  height: 14px;
  margin-right: 5.33px;
}

.learn_state {
  font-size: 14px;
  font-weight: bold;
  color: #29cca6; //已学习状态颜色
}

.no_learn_state {
  color: #ff9500; //未学习状态颜色
}

.chapter_list {
  position: relative;
}


.learn_img {
  width: 12.67px;
  height: 12.67px;
  margin-right: 5px;
}

.learn_btn {
  width: 88.33px;
  height: 33.33px;
  line-height: 33.33px;
  color: #ffffff;
  background: linear-gradient(0deg, #ffffff -20%, rgba(255, 255, 255, 0) 20%),
    #0aa7f4;
  border-radius: 6.67px;
  font-size: 12.67px;
}

.no_data_txt {
  margin: 33.33px 0;
  font-size: 10.67px;
  color: #555555;
  text-align: center;
}
</style>